package com.weimei.conversionTreasure.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.weimei.conversionTreasure.R;
import com.weimei.conversionTreasure.app.AppViewModelFactory;
import com.weimei.conversionTreasure.databinding.ActivityAddRecordBinding;
import com.weimei.conversionTreasure.utils.ValidateUtils;
import com.weimei.conversionTreasure.viewModel.AddRecordVM;
import com.weimei.conversionTreasure.viewModel.LoginVM;

import me.goldze.mvvmhabit.base.BaseActivity;
import me.goldze.mvvmhabit.base.ViewModelFactory;
import me.tatarka.bindingcollectionadapter2.BR;

public class AddRecordActivity extends BaseActivity<ActivityAddRecordBinding, AddRecordVM> {

    String flag,id;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_add_record;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initParam() {
        super.initParam();
        flag = getIntent().getStringExtra("flag");
        id = getIntent().getStringExtra("id");
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setmActivity(this,binding.back);
        binding.back.setOnClickListener(view -> finish());

        if (ValidateUtils.isNotEmptyString(flag)){
            viewModel.getData(flag,id);
            if (flag.equals("0")){
               selFJ();
            }else {
              selPL();
            }
        }

        binding.tvPl.setOnClickListener(view -> {
           selPL();
        });

        binding.tvFj.setOnClickListener(view -> {
            selFJ();
        });
    }

    private void selPL() {
        binding.tvPl.setTextSize(18);
        binding.tvPl.setTextColor(Color.parseColor("#2A373A"));
        binding.llPl.setVisibility(View.VISIBLE);
        binding.tvFj.setTextSize(12);
        binding.tvFj.setTextColor(Color.parseColor("#6C7D7E"));
        binding.llFj.setVisibility(View.GONE);
        viewModel.type.set("1");
    }

    private void selFJ() {
        binding.tvFj.setTextSize(18);
        binding.tvFj.setTextColor(Color.parseColor("#2A373A"));
        binding.llFj.setVisibility(View.VISIBLE);
        binding.tvPl.setTextSize(12);
        binding.tvPl.setTextColor(Color.parseColor("#6C7D7E"));
        binding.llPl.setVisibility(View.GONE);
        viewModel.type.set("0");
    }


    @Override
    public AddRecordVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, (ViewModelProvider.Factory) factory).get(AddRecordVM.class);
    }
}